package com.vhall.component.controller.rbac.inner;


import com.vhall.component.entity.rbac.vo.RoleVO;
import com.vhall.component.framework.common.annotation.VhallComponent;
import com.vhall.component.service.rbac.RbacInitialization;
import com.vhall.component.service.rbac.RbacRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;


/**
 * @author dalong
 * @date 2021-05-12 20:55
 */
@Slf4j
@VhallComponent
public class RbacRoleInnerController implements RbacRoleInnerFacade {

    @Autowired
    private RbacRoleService roleService;

    @Autowired
    private RbacInitialization initialization;

    @Override
    public RoleVO getInfoByRoleId(@RequestParam("role_id") Integer roleId) {
        return roleService.getInfoById(roleId);
    }

    @Override
    public String initCache() {
        try {
            log.warn("========> 初始化角色权限信息 start");
            List<RoleVO> roles = roleService.listAllRole();
            for (RoleVO role : roles) {
                initialization.doInit(role.getRoleId());
            }
            log.warn("========> 初始化角色权限信息 ends");
        } catch (Exception ex) {
            throw ex;
        }
        return "success";
    }
}
